package minNumber;

import java.util.Set;

public class Solution {
    public int minNumber(int[] nums1, int[] nums2) {
//        int mask1 = 0, mask2 = 0;
//        for (int x : nums1) mask1 |= 1 << x;
//        for (int x : nums2) mask2 |= 1 << x;
//        int m = mask1 & mask2;
//        if (m > 0) return Integer.numberOfTrailingZeros(m);
//        int x = Integer.numberOfTrailingZeros(mask1);
//        int y = Integer.numberOfTrailingZeros(mask2);
//        return Math.min(x * 10 + y, y * 10 + x);
        int[] mask1 = new int[10];
        int min = 10;
        for (int i = 0; i < nums1.length; i++) {
            mask1[nums1[i]] = 1;
            min = Math.min(min,nums1[i]);
        }
        int ans = 0;
        for (int i = 0; i < nums2.length; i++) {
            int t;
            if(nums1[nums2[i]] == 1) {
                t = nums2[i];
            } else {
                // 和最小的组成
                t = Math.min(min*10+nums2[i],nums2[i]*10+min);
            }
            ans = Math.min(ans,t);
        }
        return ans;
    }
}
